this.BX=this.BX||{};this.BX.UI=this.BX.UI||{};(function(e,t,i){"use strict";var r={INIT:"init",ADDED:"added",LOADING:"loading",PENDING:"pending",UPLOADING:"uploading",ABORTED:"aborted",COMPLETE:"complete",LOAD_FAILED:"load-failed",UPLOAD_FAILED:"upload-failed"};var n={CLIENT:"client",SERVER:"server"};var l=function(e){babelHelpers.inherits(t,e);function t(e){var i;babelHelpers.classCallCheck(this,t);i=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this));i.setEventNamespace("BX.UI.FileUploader.UploadController");i.server=e;return i}babelHelpers.createClass(t,[{key:"getServer",value:function e(){return this.server}},{key:"upload",value:function e(t){throw new Error("You must implement upload() method.")}},{key:"abort",value:function e(){throw new Error("You must implement abort() method.")}}]);return t}(t.EventEmitter);var a=function(e){babelHelpers.inherits(t,e);function t(e){var i;babelHelpers.classCallCheck(this,t);i=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this));i.setEventNamespace("BX.UI.FileUploader.LoadController");i.server=e;return i}babelHelpers.createClass(t,[{key:"getServer",value:function e(){return this.server}},{key:"load",value:function e(t){throw new Error("You must implement load() method.")}},{key:"abort",value:function e(){throw new Error("You must implement abort() method.")}}]);return t}(t.EventEmitter);var s=window.crypto||window.msCrypto;var o=function e(){return"".concat(1e7,"-",1e3,"-",4e3,"-",8e3,"-",1e11).replace(/[018]/g,(function(e){return(e^s.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)}))};var u=function e(t){if(!i.Type.isStringFilled(t)){return""}var r=t.split("/").pop();if(/javascript/.test(r)){return"js"}if(/plain/.test(r)){return"txt"}if(/svg/.test(r)){return"svg"}if(/[a-z]+/.test(r)){return r}return""};var h=0;var f=function e(t,r){if(!i.Type.isStringFilled(r)){var n=new Date;r="File ".concat(n.getFullYear(),"-").concat(n.getMonth(),"-").concat(n.getDate(),"-").concat(++h);var l=u(t.type);if(l){r+=".".concat(l)}}try{return new File([t],r,{lastModified:Date.now(),lastModifiedDate:new Date,type:t.type})}catch(e){var a=t.slice(0,t.size,t.type);a.name=r;a.lastModified=Date.now();a.lastModifiedDate=new Date;return a}};var c=/^data:((?:\w+\/(?:(?!;).)+)?)((?:;[\w\W]*?[^;])*),(.+)$/;var d=function e(t){return typeof t==="string"?t.match(c):false};var p=function e(t){var i=atob(t.split(",")[1]);var r=t.split(",")[0].split(":")[1].split(";")[0];var n=new ArrayBuffer(i.length);var l=new Uint8Array(n);for(var a=0;a<i.length;a++){l[a]=i.charCodeAt(a)}return new Blob([n],{type:r})};var v=function e(t){var r=i.Type.isStringFilled(t)?t.lastIndexOf("."):-1;return r>0?t.substring(r+1):""};var g=["jpg","bmp","jpeg","jpe","gif","png","webp"];var b=function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var n=i.Type.isFile(t)?t.name:t;var l=i.Type.isFile(t)?t.type:r;var a=v(n).toLowerCase();if(g.includes(a)){if(l===null||/^image/.test(l)){return true}}return false};var y=function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1024;var n=0;var l=T();while(t>=r&&l[n+1]){t/=r;n++}return(i.Type.isInteger(t)?t:t.toFixed(1))+l[n]};var m=null;var T=function e(){if(m!==null){return m}var t=i.Loc.getMessage("UPLOADER_FILE_SIZE_POSTFIXES").split(/[|]/);m=i.Type.isArrayFilled(t)?t:["B","kB","MB","GB","TB"];return m};function F(e,t,i){if(!t.has(e)){throw new TypeError("attempted to get private field on non-instance")}return i}var w=new WeakSet;var H=function(e){babelHelpers.inherits(l,e);function l(e){var t;var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};babelHelpers.classCallCheck(this,l);t=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(l).call(this));w.add(babelHelpers.assertThisInitialized(t));babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"id",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"file",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"serverId",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"name","");babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"originalName",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"size",0);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"type","");babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"width",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"height",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"clientPreview",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"clientPreviewUrl",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"clientPreviewWidth",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"clientPreviewHeight",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"serverPreviewUrl",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"serverPreviewWidth",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"serverPreviewHeight",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"downloadUrl",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"removeUrl",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"status",r.INIT);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"origin",n.CLIENT);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"uploadController",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"loadController",null);t.setEventNamespace("BX.UI.FileUploader.File");var s=i.Type.isPlainObject(a)?a:{};if(i.Type.isFile(e)){t.file=e}else if(i.Type.isBlob(e)){t.file=f(e,s.name||e.name)}else if(d(e)){var u=p(e);t.file=f(u,s.name)}else if(i.Type.isNumber(e)||i.Type.isStringFilled(e)){t.origin=n.SERVER;t.serverId=e;if(i.Type.isPlainObject(s)){t.setFile(s)}}t.id=i.Type.isStringFilled(s.id)?s.id:o();t.subscribeFromOptions(s.events);t.fireStateChangeEvent=i.Runtime.debounce(t.fireStateChangeEvent,0,babelHelpers.assertThisInitialized(t));return t}babelHelpers.createClass(l,[{key:"load",value:function e(){if(!this.canLoad()){return}this.setStatus(r.LOADING);this.emit("onLoadStart");this.loadController.load(this)}},{key:"upload",value:function e(){var n=this;if(!this.canUpload()){return}var l=new t.BaseEvent({data:{file:this}});this.emit("onBeforeUpload",l);if(l.isDefaultPrevented()){return}this.setStatus(r.UPLOADING);l=new t.BaseEvent({data:{file:this.getFile()}});this.emitAsync("onPrepareFileAsync",l).then((function(e){var t=i.Type.isArrayFilled(e)&&i.Type.isFile(e[0])?e[0]:n.getFile();n.emit("onUploadStart");if(n.uploadController){n.uploadController.upload(t)}})).catch((function(e){console.error(e)}))}},{key:"abort",value:function e(){if(this.uploadController){this.uploadController.abort()}this.setStatus(r.ABORTED);this.emit("onAbort")}},{key:"abortLoad",value:function e(){if(this.loadController){this.loadController.abort()}this.setStatus(r.ABORTED);this.emit("onAbort")}},{key:"retry",value:function e(){}},{key:"cancel",value:function e(){this.abort();this.emit("onCancel")}},{key:"setUploadController",value:function e(t){this.uploadController=t}},{key:"setLoadController",value:function e(t){this.loadController=t}},{key:"isReadyToUpload",value:function e(){return this.getStatus()===r.PENDING}},{key:"isUploadable",value:function e(){return this.uploadController!==null}},{key:"isLoadable",value:function e(){return this.loadController!==null}},{key:"canUpload",value:function e(){return this.isReadyToUpload()&&this.isUploadable()}},{key:"canLoad",value:function e(){return this.getStatus()===r.ADDED&&this.isLoadable()}},{key:"isUploading",value:function e(){return this.getStatus()===r.UPLOADING}},{key:"isLoading",value:function e(){return this.getStatus()===r.LOADING}},{key:"isComplete",value:function e(){return this.getStatus()===r.COMPLETE}},{key:"isFailed",value:function e(){return this.getStatus()===r.LOAD_FAILED||this.getStatus()===r.UPLOAD_FAILED}},{key:"getFile",value:function e(){return this.file}},{key:"setFile",value:function e(t){if(i.Type.isFile(t)){this.file=t}else if(i.Type.isPlainObject(t)){this.setName(t.name);this.setOriginalName(t.originalName);this.setType(t.type);this.setSize(t.size);this.setServerId(t.serverId);this.setWidth(t.width);this.setHeight(t.height);this.setClientPreview(t.clientPreview,t.clientPreviewWidth,t.clientPreviewHeight);this.setServerPreview(t.serverPreviewUrl,t.serverPreviewWidth,t.serverPreviewHeight);this.setDownloadUrl(t.downloadUrl);this.setRemoveUrl(t.removeUrl)}}},{key:"getName",value:function e(){return this.getFile()?this.getFile().name:this.name}},{key:"setName",value:function e(t){if(i.Type.isStringFilled(t)){F(this,w,P).call(this,"name",t)}}},{key:"getOriginalName",value:function e(){return this.originalName?this.originalName:this.getName()}},{key:"setOriginalName",value:function e(t){if(i.Type.isStringFilled(t)){F(this,w,P).call(this,"originalName",t)}}},{key:"getExtension",value:function e(){var t=this.getName().lastIndexOf(".");return t>0?this.getName().substring(t+1).toLowerCase():""}},{key:"getType",value:function e(){return this.getFile()?this.getFile().type:this.type}},{key:"setType",value:function e(t){if(i.Type.isStringFilled(t)){F(this,w,P).call(this,"type",t)}}},{key:"getSize",value:function e(){return this.getFile()?this.getFile().size:this.size}},{key:"getSizeFormatted",value:function e(){return y(this.getSize())}},{key:"setSize",value:function e(t){if(i.Type.isNumber(t)&&t>=0){F(this,w,P).call(this,"size",t)}}},{key:"getId",value:function e(){return this.id}},{key:"getServerId",value:function e(){return this.serverId}},{key:"setServerId",value:function e(t){if(i.Type.isNumber(t)||i.Type.isStringFilled(t)){F(this,w,P).call(this,"serverId",t)}}},{key:"getStatus",value:function e(){return this.status}},{key:"setStatus",value:function e(t){F(this,w,P).call(this,"status",t);this.emit("onStatusChange")}},{key:"getOrigin",value:function e(){return this.origin}},{key:"getDownloadUrl",value:function e(){return this.downloadUrl}},{key:"setDownloadUrl",value:function e(t){if(i.Type.isStringFilled(t)){F(this,w,P).call(this,"downloadUrl",t)}}},{key:"getRemoveUrl",value:function e(){return this.removeUrl}},{key:"setRemoveUrl",value:function e(t){if(i.Type.isStringFilled(t)){F(this,w,P).call(this,"removeUrl",t)}}},{key:"getWidth",value:function e(){return this.width}},{key:"setWidth",value:function e(t){if(i.Type.isNumber(t)){F(this,w,P).call(this,"width",t)}}},{key:"getHeight",value:function e(){return this.height}},{key:"setHeight",value:function e(t){if(i.Type.isNumber(t)){F(this,w,P).call(this,"height",t)}}},{key:"getPreviewUrl",value:function e(){return this.getClientPreview()?this.getClientPreviewUrl():this.getServerPreviewUrl()}},{key:"getPreviewWidth",value:function e(){return this.getClientPreview()?this.getClientPreviewWidth():this.getServerPreviewWidth()}},{key:"getPreviewHeight",value:function e(){return this.getClientPreview()?this.getClientPreviewHeight():this.getServerPreviewHeight()}},{key:"getClientPreview",value:function e(){return this.clientPreview}},{key:"setClientPreview",value:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;if(i.Type.isFile(t)||i.Type.isNull(t)){this.revokeClientPreviewUrl();F(this,w,P).call(this,"clientPreview",t);F(this,w,P).call(this,"clientPreviewWidth",r);F(this,w,P).call(this,"clientPreviewHeight",n)}}},{key:"getClientPreviewUrl",value:function e(){if(this.clientPreviewUrl===null&&this.getClientPreview()!==null){this.clientPreviewUrl=URL.createObjectURL(this.getClientPreview())}return this.clientPreviewUrl}},{key:"revokeClientPreviewUrl",value:function e(){if(this.clientPreviewUrl!==null){URL.revokeObjectURL(this.clientPreviewUrl)}this.clientPreviewUrl=null}},{key:"getClientPreviewWidth",value:function e(){return this.clientPreviewWidth}},{key:"getClientPreviewHeight",value:function e(){return this.clientPreviewHeight}},{key:"getServerPreviewUrl",value:function e(){return this.serverPreviewUrl}},{key:"setServerPreview",value:function e(t){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;if(i.Type.isStringFilled(t)||i.Type.isNull(t)){F(this,w,P).call(this,"serverPreviewUrl",t);F(this,w,P).call(this,"serverPreviewWidth",r);F(this,w,P).call(this,"serverPreviewHeight",n)}}},{key:"getServerPreviewWidth",value:function e(){return this.serverPreviewWidth}},{key:"getServerPreviewHeight",value:function e(){return this.serverPreviewHeight}},{key:"isImage",value:function e(){return b(this.getOriginalName(),this.getType())}},{key:"getState",value:function e(){return JSON.parse(JSON.stringify(this))}},{key:"fireStateChangeEvent",value:function e(){this.emit("onStateChange")}},{key:"toJSON",value:function e(){return{id:this.getId(),serverId:this.getServerId(),status:this.getStatus(),name:this.getName(),originalName:this.getOriginalName(),size:this.getSize(),sizeFormatted:this.getSizeFormatted(),type:this.getType(),extension:this.getExtension(),origin:this.getOrigin(),isImage:this.isImage(),width:this.getWidth(),height:this.getHeight(),previewUrl:this.getPreviewUrl(),previewWidth:this.getPreviewWidth(),previewHeight:this.getPreviewHeight(),clientPreviewUrl:this.getClientPreviewUrl(),clientPreviewWidth:this.getClientPreviewWidth(),clientPreviewHeight:this.getClientPreviewHeight(),serverPreviewUrl:this.getServerPreviewUrl(),serverPreviewWidth:this.getServerPreviewWidth(),serverPreviewHeight:this.getServerPreviewHeight(),downloadUrl:this.getDownloadUrl(),removeUrl:this.getRemoveUrl()}}}]);return l}(t.EventEmitter);var P=function e(t,i){this[t]=i;this.fireStateChangeEvent()};var S=function(e){babelHelpers.inherits(t,e);function t(e){var r,n;var l;babelHelpers.classCallCheck(this,t);var a=i.Type.isString(arguments.length<=1?undefined:arguments[1])?arguments.length<=1?undefined:arguments[1]:null;var s=i.Type.isString(arguments.length<=2?undefined:arguments[2])?arguments.length<=2?undefined:arguments[2]:null;var o=i.Type.isPlainObject((r=(arguments.length<=1?0:arguments.length-1)-1+1,r<1||arguments.length<=r?undefined:arguments[r]))?(n=(arguments.length<=1?0:arguments.length-1)-1+1,n<1||arguments.length<=n?undefined:arguments[n]):{};var u={};Object.keys(o).forEach((function(e){u["#".concat(e,"#")]=o[e]}));if(!i.Type.isString(a)&&i.Loc.hasMessage("UPLOADER_".concat(e))){a=i.Loc.getMessage("UPLOADER_".concat(e),u)}if(i.Type.isStringFilled(a)&&!i.Type.isString(s)&&i.Loc.hasMessage("UPLOADER_".concat(e,"_DESC"))){s=i.Loc.getMessage("UPLOADER_".concat(e,"_DESC"),u)}l=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,a,e,o));babelHelpers.defineProperty(babelHelpers.assertThisInitialized(l),"description","");babelHelpers.defineProperty(babelHelpers.assertThisInitialized(l),"origin","client");l.setDescription(s);return l}babelHelpers.createClass(t,[{key:"getDescription",value:function e(){return this.description}},{key:"setDescription",value:function e(t){if(i.Type.isString(t)){this.description=t}return this}},{key:"getOrigin",value:function e(){return this.origin}},{key:"setOrigin",value:function e(t){if(i.Type.isStringFilled(t)){this.origin=t}return this}},{key:"clone",value:function e(){var i=JSON.parse(JSON.stringify(this));var r=new t(i.code,i.message,i.description,i.customData);r.setOrigin(i.origin);return r}},{key:"toJSON",value:function e(){return{code:this.getCode(),message:this.getMessage(),description:this.getDescription(),origin:this.getOrigin(),customData:this.getCustomData()}}}],[{key:"createFromAjaxErrors",value:function e(t){if(!i.Type.isArrayFilled(t)||!i.Type.isPlainObject(t[0])){return new this("SERVER_ERROR")}var r=t.find((function(e){return e.type==="file-uploader"}));if(r&&!r.system){var n=r.code,l=r.message,a=r.description,s=r.customData;var o=new this(n,l,a,s);o.setOrigin("server");return o}else{var u=t[0],h=u.code,f=u.message;if(h==="NETWORK_ERROR"){f=i.Loc.getMessage("UPLOADER_SERVER_ERROR")}else{h="SERVER_ERROR";f=null}console.error("FileUploader",t);var c=new this(h,f);c.setOrigin("server");return c}}}]);return t}(i.BaseError);var k=function(){function e(t,i){babelHelpers.classCallCheck(this,e);babelHelpers.defineProperty(this,"data",null);babelHelpers.defineProperty(this,"offset",0);babelHelpers.defineProperty(this,"retries",[]);this.data=t;this.offset=i}babelHelpers.createClass(e,[{key:"getNextRetryDelay",value:function e(){if(this.retries.length===0){return null}return this.retries.shift()}},{key:"setRetries",value:function e(t){if(i.Type.isArray(t)){this.retries=t}}},{key:"getData",value:function e(){return this.data}},{key:"getOffset",value:function e(){return this.offset}},{key:"getSize",value:function e(){return this.getData().size}}]);return e}();function C(e,t,i){if(!t.has(e)){throw new TypeError("attempted to get private field on non-instance")}return i}var z=new WeakSet;var E=new WeakSet;var I=new WeakSet;var U=function(e){babelHelpers.inherits(t,e);function t(e){var i;babelHelpers.classCallCheck(this,t);i=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,e));I.add(babelHelpers.assertThisInitialized(i));E.add(babelHelpers.assertThisInitialized(i));z.add(babelHelpers.assertThisInitialized(i));babelHelpers.defineProperty(babelHelpers.assertThisInitialized(i),"file",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(i),"chunkOffset",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(i),"chunkTimeout",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(i),"token",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(i),"xhr",null);return i}babelHelpers.createClass(t,[{key:"upload",value:function e(t){if(this.chunkOffset!==null){return}this.file=t;var i=C(this,I,D).call(this);if(i){C(this,z,O).call(this,i)}}},{key:"abort",value:function e(){if(this.xhr){this.xhr.abort();this.xhr=null}clearTimeout(this.chunkTimeout)}},{key:"getFile",value:function e(){return this.file}},{key:"getChunkSize",value:function e(){return this.getServer().getChunkSize()}},{key:"getChunkOffset",value:function e(){return this.chunkOffset}},{key:"getToken",value:function e(){return this.token}},{key:"setToken",value:function e(t){if(i.Type.isStringFilled(t)){this.token=t}}}]);return t}(l);var O=function e(t){var r=this;var n=this.getFile().size;var l=t.getOffset()===0&&n===t.getSize();var a=this.getFile().name;if(a.normalize){a=a.normalize()}var s=[{name:"Content-Type",value:this.getFile().type},{name:"X-Upload-Content-Name",value:encodeURIComponent(a)}];if(!l){var o=t.getOffset();var u=t.getOffset()+t.getSize()-1;var h="bytes ".concat(o,"-").concat(u,"/").concat(n);s.push({name:"Content-Range",value:h})}var f=this.getServer().getControllerOptions();i.ajax.runAction("ui.fileuploader.upload",{headers:s,data:t.getData(),preparePost:false,getParameters:{controller:this.getServer().getController(),controllerOptions:f?JSON.stringify(f):null,token:this.getToken()||""},onrequeststart:function e(t){r.xhr=t},onprogressupload:function e(i){if(i.lengthComputable){var n=r.getFile().size;var l=Math.min(n,t.getOffset()+i.loaded);var a=n>0?Math.floor(l/n*100):100;r.emit("onProgress",{progress:a})}}}).then((function(i){console.log("response",i);if(i.data.token){r.setToken(i.data.token);var n=r.getFile().size;var l=n>0?Math.floor((t.getOffset()+t.getSize())/n*100):100;r.emit("onProgress",{progress:l});var a=C(r,I,D).call(r);if(a){C(r,z,e).call(r,a)}else{r.emit("onProgress",{progress:100});r.emit("onUpload",{fileInfo:i.data.file})}}else{r.emit("onError",{error:new S("SERVER_ERROR")})}})).catch((function(e){console.log("error",e);var i=S.createFromAjaxErrors(e.errors);var n=i.getCode()==="NETWORK_ERROR";if(!n||!C(r,E,A).call(r,t)){r.emit("onError",{error:i})}}))};var A=function e(t){var i=this;var r=t.getNextRetryDelay();if(r===null){return false}clearTimeout(this.chunkTimeout);this.chunkTimeout=setTimeout((function(){C(i,z,O).call(i,t)}),r);return true};var D=function e(){if(this.getChunkOffset()!==null&&this.getChunkOffset()>=this.getFile().size){return null}if(this.getChunkOffset()===null){this.chunkOffset=0}var t;if(this.getChunkOffset()===0&&this.getFile().size<=this.getChunkSize()){t=new k(this.getFile(),this.getChunkOffset());this.chunkOffset=this.getFile().size}else{var i=Math.min(this.getChunkSize(),this.getFile().size-this.getChunkOffset());var r=this.getChunkOffset()+i;var n=this.getFile().slice(this.getChunkOffset(),r);t=new k(n,this.getChunkOffset());this.chunkOffset=r}t.setRetries(babelHelpers.toConsumableArray(this.getServer().getChunkRetryDelays()));return t};var R=new WeakMap;function M(e,t){var r=e.getServer();var n=R.get(r);if(!n){n={tasks:[],load:i.Runtime.debounce(N,100,r),xhr:null};R.set(r,n)}n.tasks.push({controller:e,file:t});n.load()}function L(e){var t=e.getServer();var i=R.get(t);if(i){i.xhr.abort();i.xhr=null;R.delete(t)}}function N(){var e=this;var t=R.get(e);if(!t){return}var r=t.tasks;R.delete(e);var n=[];r.forEach((function(e){var t=e.controller,i=e.file;n.push(i.getServerId())}));var l=e.getControllerOptions();i.ajax.runAction("ui.fileuploader.load",{data:{fileIds:n},getParameters:{controller:e.getController(),controllerOptions:l?JSON.stringify(l):null},onrequeststart:function e(i){t.xhr=i},onprogress:function e(t){if(t.lengthComputable){var i=t.total>0?Math.floor(t.loaded/t.total*100):100;r.forEach((function(e){var t=e.controller,r=e.file;t.emit("onProgress",{file:r,progress:i})}))}}}).then((function(e){var t;if((t=e.data)!==null&&t!==void 0&&t.files){var i={};e.data.files.forEach((function(e){i[e.id]=e}));r.forEach((function(e){var t=e.controller,r=e.file;var n=i[r.getServerId()]||null;if(n&&n.success){t.emit("onProgress",{file:r,progress:100});t.emit("onLoad",{fileInfo:n.data.file})}else{var l=S.createFromAjaxErrors(n===null||n===void 0?void 0:n.errors);t.emit("onError",{error:l})}}))}else{var n=new S("SERVER_ERROR");r.forEach((function(e){var t=e.controller;t.emit("onError",{error:n.clone()})}))}})).catch((function(e){var t=S.createFromAjaxErrors(e.errors);r.forEach((function(e){var i=e.controller;i.emit("onError",{error:t.clone()})}))}))}var x=function(e){babelHelpers.inherits(t,e);function t(e){babelHelpers.classCallCheck(this,t);return babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,e))}babelHelpers.createClass(t,[{key:"load",value:function e(t){if(this.getServer().getController()){M(this,t)}else{this.emit("onProgress",{file:t,progress:100});this.emit("onLoad",{fileInfo:t})}}},{key:"abort",value:function e(){if(this.getServer().getController()){L(this)}}}]);return t}(a);var W=function(e){babelHelpers.inherits(t,e);function t(e){babelHelpers.classCallCheck(this,t);return babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,e))}babelHelpers.createClass(t,[{key:"load",value:function e(t){if(i.Type.isFile(t.getFile())){this.emit("onProgress",{file:t,progress:100});this.emit("onLoad",{fileInfo:t})}else{this.emit("onError",{error:new S("WRONG_FILE_SOURCE")})}}},{key:"abort",value:function e(){}}]);return t}(a);function B(e,t,i){if(!t.has(e)){throw new TypeError("attempted to get private field on non-instance")}return i}var _=new WeakSet;var j=function(){function e(t){var r=this;babelHelpers.classCallCheck(this,e);_.add(this);babelHelpers.defineProperty(this,"controller",null);babelHelpers.defineProperty(this,"controllerOptions",null);babelHelpers.defineProperty(this,"uploadControllerClass",null);babelHelpers.defineProperty(this,"loadControllerClass",null);babelHelpers.defineProperty(this,"chunkSize",null);babelHelpers.defineProperty(this,"defaultChunkSize",null);babelHelpers.defineProperty(this,"chunkMinSize",null);babelHelpers.defineProperty(this,"chunkMaxSize",null);babelHelpers.defineProperty(this,"chunkRetryDelays",[500,1e3,3e3]);var n=i.Type.isPlainObject(t)?t:{};this.controller=i.Type.isStringFilled(n.controller)?n.controller:null;this.controllerOptions=i.Type.isPlainObject(n.controllerOptions)?n.controllerOptions:null;var l=i.Type.isNumber(n.chunkSize)&&n.chunkSize>0?n.chunkSize:this.getDefaultChunkSize();this.chunkSize=n.forceChunkSize===true?l:B(this,_,G).call(this,l);if(n.chunkRetryDelays===false||n.chunkRetryDelays===null){this.chunkRetryDelays=[]}else if(i.Type.isArray(n.chunkRetryDelays)){this.chunkRetryDelays=n.chunkRetryDelays}["uploadControllerClass","loadControllerClass"].forEach((function(e){if(i.Type.isStringFilled(n[e])){r[e]=i.Runtime.getClass(n[e]);if(!i.Type.isFunction(n[e])){throw new Error('FileUploader.Server: "'.concat(e,'" must be a function.'))}}else if(i.Type.isFunction(n[e])){r[e]=n[e]}}))}babelHelpers.createClass(e,[{key:"createUploadController",value:function e(){if(this.uploadControllerClass){var t=new this.uploadControllerClass(this);if(!(t instanceof l)){throw new Error('FileUploader.Server: "uploadControllerClass" must be an instance of AbstractUploadController.')}return t}else if(i.Type.isStringFilled(this.controller)){return new U(this)}return null}},{key:"createLoadController",value:function e(){if(this.loadControllerClass){var t=new this.loadControllerClass(this);if(!(t instanceof a)){throw new Error('FileUploader.Server: "loadControllerClass" must be an instance of AbstractLoadController.')}return t}return new x(this)}},{key:"createClientLoadController",value:function e(){return new W(this)}},{key:"getController",value:function e(){return this.controller}},{key:"getControllerOptions",value:function e(){return this.controllerOptions}},{key:"getChunkSize",value:function e(){return this.chunkSize}},{key:"getDefaultChunkSize",value:function e(){if(this.defaultChunkSize===null){var t=i.Extension.getSettings("ui.file-uploader");this.defaultChunkSize=t.get("defaultChunkSize",5*1024*1024)}return this.defaultChunkSize}},{key:"getChunkMinSize",value:function e(){if(this.chunkMinSize===null){var t=i.Extension.getSettings("ui.file-uploader");this.chunkMinSize=t.get("chunkMinSize",1024*1024)}return this.chunkMinSize}},{key:"getChunkMaxSize",value:function e(){if(this.chunkMaxSize===null){var t=i.Extension.getSettings("ui.file-uploader");this.chunkMaxSize=t.get("chunkMaxSize",5*1024*1024)}return this.chunkMaxSize}},{key:"getChunkRetryDelays",value:function e(){return this.chunkRetryDelays}}]);return e}();var G=function e(t){return Math.min(Math.max(this.getChunkMinSize(),t),this.getChunkMaxSize())};var V=function(){function e(t){babelHelpers.classCallCheck(this,e);babelHelpers.defineProperty(this,"uploader",null);this.uploader=t}babelHelpers.createClass(e,[{key:"getUploader",value:function e(){return this.uploader}},{key:"apply",value:function e(){throw new Error("You must implement apply() method.")}}]);return e}();var X=function(e){babelHelpers.inherits(t,e);function t(e){var r;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};babelHelpers.classCallCheck(this,t);r=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,e));babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"maxFileSize",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"minFileSize",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"maxTotalFileSize",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"imageMaxFileSize",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"imageMinFileSize",null);var l=i.Type.isPlainObject(n)?n:{};var a=["maxFileSize","minFileSize","maxTotalFileSize","imageMaxFileSize","imageMinFileSize"];a.forEach((function(e){r[e]=i.Type.isNumber(l[e])&&l[e]>=0?l[e]:r[e]}));return r}babelHelpers.createClass(t,[{key:"apply",value:function e(t){var i=this;return new Promise((function(e,r){if(i.maxFileSize!==null&&t.getSize()>i.maxFileSize){r(new S("MAX_FILE_SIZE_EXCEEDED",{maxFileSize:y(i.maxFileSize),maxFileSizeInBytes:i.maxFileSize}));return}if(i.minFileSize!==null&&t.getSize()<i.minFileSize){r(new S("MIN_FILE_SIZE_EXCEEDED",{minFileSize:y(i.minFileSize),minFileSizeInBytes:i.minFileSize}));return}if(t.isImage()){if(i.imageMaxFileSize!==null&&t.getSize()>i.imageMaxFileSize){r(new S("IMAGE_MAX_FILE_SIZE_EXCEEDED",{imageMaxFileSize:y(i.imageMaxFileSize),imageMaxFileSizeInBytes:i.imageMaxFileSize}));return}if(i.imageMinFileSize!==null&&t.getSize()<i.imageMinFileSize){r(new S("IMAGE_MIN_FILE_SIZE_EXCEEDED",{imageMinFileSize:y(i.imageMinFileSize),imageMinFileSizeInBytes:i.imageMinFileSize}));return}}if(i.maxTotalFileSize!==null){if(i.getUploader().getTotalSize()>i.maxTotalFileSize){r(new S("MAX_TOTAL_FILE_SIZE_EXCEEDED",{maxTotalFileSize:y(i.maxTotalFileSize),maxTotalFileSizeInBytes:i.maxTotalFileSize}));return}}e()}))}}]);return t}(V);var J=function e(t,r){if(!i.Type.isArrayFilled(r)){return true}var n=t.type;var l=n.replace(/\/.*$/,"");for(var a=0;a<r.length;a++){if(!i.Type.isStringFilled(r[a])){continue}var s=r[a].trim().toLowerCase();if(s.charAt(0)==="."){if(t.name.toLowerCase().indexOf(s,t.name.length-s.length)!==-1){return true}}else if(/\/\*$/.test(s)){if(l===s.replace(/\/.*$/,"")){return true}}else if(n===s){return true}}return false};var Q=function(e){babelHelpers.inherits(t,e);function t(e){babelHelpers.classCallCheck(this,t);return babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,e))}babelHelpers.createClass(t,[{key:"apply",value:function e(t){var i=this;return new Promise((function(e,r){if(J(t.getFile(),i.getUploader().getAcceptedFileTypes())){e()}else{r(new S("FILE_TYPE_NOT_ALLOWED"))}}))}}]);return t}(V);var Y=function e(t){return new Promise((function(e,i){var r=new FileReader;r.readAsArrayBuffer(t);r.onload=function(){var t=r.result;e(t)};r.onerror=function(){i(r.error)}}))};var q=function e(t){var i=[];for(var r=0;r<t.length;r++){i.push(t.charCodeAt(r)&255)}return i};var Z=function e(t,i,r){for(var n=r,l=0;l<i.length;){if(t.getUint8(n++)!==i[l++]){return false}}return true};var $=q("GIF87a");var K=q("GIF89a");var ee=function(){function e(){babelHelpers.classCallCheck(this,e)}babelHelpers.createClass(e,[{key:"getSize",value:function e(t){return new Promise((function(e,i){if(t.size<10){return e(null)}var r=t.slice(0,10);Y(r).then((function(t){var i=new DataView(t);if(!Z(i,$,0)&&!Z(i,K,0)){return e(null)}e({width:i.getUint16(6,true),height:i.getUint16(8,true)})})).catch((function(){e(null)}))}))}}]);return e}();var te=q("\x89PNG\r\n\x1a\n");var ie=q("IHDR");var re=q("CgBI");var ne=function(){function e(){babelHelpers.classCallCheck(this,e)}babelHelpers.createClass(e,[{key:"getSize",value:function e(t){return new Promise((function(e,i){if(t.size<40){return e(null)}var r=t.slice(0,40);Y(r).then((function(t){var i=new DataView(t);if(!Z(i,te,0)){return e(null)}if(Z(i,re,12)){if(Z(i,ie,28)){e({width:i.getUint32(32),height:i.getUint32(36)})}else{e(null)}}else if(Z(i,ie,12)){e({width:i.getUint32(16),height:i.getUint32(20)})}else{e(null)}})).catch((function(){e(null)}))}))}}]);return e}();var le=16973;var ae=function(){function e(){babelHelpers.classCallCheck(this,e)}babelHelpers.createClass(e,[{key:"getSize",value:function e(t){return new Promise((function(e,i){if(t.size<26){return e(null)}var r=t.slice(0,26);Y(r).then((function(t){var i=new DataView(t);if(!i.getUint16(0)===le){return e(null)}e({width:i.getUint32(18,true),height:Math.abs(i.getInt32(22,true))})})).catch((function(){e(null)}))}))}}]);return e}();var se=q("Exif\0\0");var oe=function(){function e(){babelHelpers.classCallCheck(this,e)}babelHelpers.createClass(e,[{key:"getSize",value:function e(t){return new Promise((function(e,i){if(t.size<2){return e(null)}Y(t).then((function(t){var i=new DataView(t);if(i.getUint8(0)!==255||i.getUint8(1)!==216){e(null)}var r=2;var n=-1;for(;;){if(i.byteLength-r<2){return e(null)}if(i.getUint8(r++)!==255){return e(null)}var l=i.getUint8(r++);var a=void 0;while(l===255){l=i.getUint8(r++)}if(208<=l&&l<=217||l===1){a=0}else if(192<=l&&l<=254){if(i.byteLength-r<2){return e(null)}a=i.getUint16(r)-2;r+=2}else{return e(null)}if(l===217||l===218){return e(null)}if(l===225&&a>=10&&Z(i,se,r)){var s=new DataView(i.buffer,r+6,r+a);n=he(s)}if(a>=5&&192<=l&&l<=207&&l!==196&&l!==200&&l!==204){if(i.byteLength-r<a){return e(null)}var o=i.getUint16(r+3);var u=i.getUint16(r+1);if(n>=5&&n<=8){var h=[u,o];o=h[0];u=h[1]}return e({width:o,height:u,orientation:n})}r+=a}})).catch((function(){e(null)}))}))}}]);return e}();var ue={BIG_ENDIAN:19789,LITTLE_ENDIAN:18761};var he=function e(t){var i=t.getUint16(0);var r=i===ue.BIG_ENDIAN;var n=i===ue.LITTLE_ENDIAN;if(r||n){return fe(t,n)}return-1};var fe=function e(t){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var r=8;var n=t.getUint16(r,i);var l=12;var a=2;for(var s=0;s<n;s++){var o=r+a+s*l;var u=o+l;if(o>t.byteLength){return-1}var h=new DataView(t.buffer,t.byteOffset+o,u-o);var f=h.getUint16(0,i);if(f===274){var c=h.getUint16(2,i);if(c!==3){return-1}var d=h.getUint32(4,i);if(d!==1){return-1}return h.getUint16(8,i)}}};var ce=1380533830;var de=1464156752;var pe=1448097824;var ve=1448097868;var ge=1448097880;var be=function(){function e(){babelHelpers.classCallCheck(this,e)}babelHelpers.createClass(e,[{key:"getSize",value:function e(t){return new Promise((function(e,i){if(t.size<16){return e(null)}var r=t.slice(0,30);Y(r).then((function(t){var i=new DataView(t);if(i.getUint32(0)!==ce&&i.getUint32(8)!==de){return e(null)}var r=i.getUint32(12);var n=new DataView(t,20,10);if(r===pe&&n.getUint8(0)!==47){e({width:n.getUint16(6,true)&16383,height:n.getUint16(8,true)&16383});return}else if(r===ve&&n.getUint8(0)===47){var l=n.getUint32(1,true);e({width:(l&16383)+1,height:(l>>14&16383)+1});return}else if(r===ge){var a=n.getUint8(0);var s=(a&192)===0;var o=(a&1)===0;if(s&&o){var u=1+(n.getUint8(6)<<16|n.getUint8(5)<<8|n.getUint8(4));var h=1+(n.getUint8(9)<<0|n.getUint8(8)<<8|n.getUint8(7));e({width:u,height:h});return}}e(null)})).catch((function(){e(null)}))}))}}]);return e}();var ye=new oe;var me={gif:new ee,png:new ne,bmp:new ae,jpg:ye,jpeg:ye,jpe:ye,webp:new be};var Te=function e(t){if(t.size===0){return Promise.resolve(null)}var i=v(t.name).toLowerCase();var r=t.type.replace(/^image\//,"");var n=me[i]||me[r];if(!n){return Promise.resolve(null)}return n.getSize(t)};var Fe=function(e){babelHelpers.inherits(t,e);function t(e){var r;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};babelHelpers.classCallCheck(this,t);r=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,e));babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"imageMinWidth",1);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"imageMinHeight",1);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"imageMaxWidth",1e4);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"imageMaxHeight",1e4);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"ignoreUnknownImageTypes",false);var l=i.Type.isPlainObject(n)?n:{};["imageMinWidth","imageMinHeight","imageMaxWidth","imageMaxHeight"].forEach((function(e){r[e]=i.Type.isNumber(l[e])&&l[e]>0?l[e]:r[e]}));if(i.Type.isBoolean(l["ignoreUnknownImageTypes"])){r.ignoreUnknownImageTypes=l["ignoreUnknownImageTypes"]}return r}babelHelpers.createClass(t,[{key:"apply",value:function e(t){var i=this;return new Promise((function(e,r){if(!t.isImage()){e();return}Te(t.getFile()).then((function(n){var l=n.width,a=n.height;t.setWidth(l);t.setHeight(a);if(l<i.imageMinWidth||a<i.imageMinHeight){r(new S("IMAGE_IS_TOO_SMALL",{minWidth:i.imageMinWidth,minHeight:i.imageMinHeight}))}else if(l>i.imageMaxWidth||a>i.imageMaxHeight){r(new S("IMAGE_IS_TOO_BIG",{maxWidth:i.imageMaxWidth,maxHeight:i.imageMaxHeight}))}else{e()}})).catch((function(){if(i.ignoreUnknownImageTypes){e()}else{r(new S("IMAGE_TYPE_NOT_SUPPORTED"))}}))}))}}]);return t}(V);var we=function e(t){var i=new Blob(["(",t.toString(),")()"],{type:"application/javascript"});var r=URL.createObjectURL(i);var n=new Worker(r);return{post:function e(t,i,r){var l=o();n.onmessage=function(e){if(e.data.id===l){i(e.data.message)}};n.postMessage({id:l,message:t},r)},terminate:function e(){n.terminate();URL.revokeObjectURL(r)}}};var He=function e(){self.onmessage=function(e){createImageBitmap(e.data.message.file).then((function(t){self.postMessage({id:e.data.id,message:t},[t])})).catch((function(){self.postMessage({id:e.data.id,message:null},[])}))}};var Pe=function e(t){return new Promise((function(e,i){var r=document.createElement("img");var n=URL.createObjectURL(t);r.src=n;r.onerror=function(e){URL.revokeObjectURL(r.src);i(e)};r.onload=function(){URL.revokeObjectURL(n);e({width:r.naturalWidth,height:r.naturalHeight,image:r})}}))};var Se=function e(t,i,r){i=Math.round(i);r=Math.round(r);var n=document.createElement("canvas");n.width=i;n.height=r;var l=n.getContext("2d");l.drawImage(t,0,0,i,r);return n};var ke=function e(t){return t.substr(0,t.lastIndexOf("."))||t};var Ce={jpeg:"jpg"};var ze=function e(t,i){var r=ke(t);var n=i.split("/")[1];var l=Ce[n]||n;return"".concat(r,".").concat(l)};var Ee=window.HTMLCanvasElement&&window.HTMLCanvasElement.prototype;var Ie=window.HTMLCanvasElement&&Ee.toBlob;var Ue=function e(t,i,r){return new Promise((function(e,n){if(Ie){t.toBlob((function(t){e(t)}),i,r)}else{var l=p(t.toDataURL(i,r));e(l)}}))};var Oe="createImageBitmap"in window&&typeof ImageBitmap!=="undefined"&&ImageBitmap.prototype&&ImageBitmap.prototype.close;var Ae=function e(t,i){return new Promise((function(e,r){var n=function e(){Pe(t).then((function(e){var t=e.image;l(t)})).catch((function(e){r(e)}))};var l=function n(l){var a=De(l,i),s=a.targetWidth,o=a.targetHeight;if(!s||!o){if("close"in l){l.close()}e({preview:t,width:l.width,height:l.height});return}var u=Se(l,s,o);if("close"in l){l.close()}var h=i.quality,c=h===void 0?.92:h,d=i.mimeType,p=d===void 0?"image/jpeg":d;var v=/jpeg|png|webp/.test(t.type)?t.type:p;Ue(u,v,c).then((function(i){var r=ze(t.name,v);var n=f(i,r);e({preview:n,width:s,height:o})})).catch((function(){r()}))};if(Oe){var a=we(He);a.post({file:t},(function(e){a.terminate();if(e){l(e)}else{n()}}))}else{n()}}))};var De=function e(t){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var r=i.mode,n=r===void 0?"contain":r,l=i.upscale,a=l===void 0?false:l,s=i.width,o=i.height;var u={targetWidth:0,targetHeight:0};if(!s&&!o){return u}if(s===null){s=o}else if(o===null){o=s}if(n!=="force"){var h=s/t.width;var f=o/t.height;var c=1;if(n==="cover"){c=Math.max(h,f)}else if(n==="contain"){c=Math.min(h,f)}if(c>1&&a===false){return u}s=t.width*c;o=t.height*c}u.targetWidth=Math.round(s);u.targetHeight=Math.round(o);return u};var Re=function(e){babelHelpers.inherits(t,e);function t(e){var r;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};babelHelpers.classCallCheck(this,t);r=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,e));babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"imagePreviewWidth",300);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"imagePreviewHeight",300);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"imagePreviewQuality",.92);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"imagePreviewMimeType","image/jpeg");babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"imagePreviewUpscale",false);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"imagePreviewResizeMethod","contain");var l=i.Type.isPlainObject(n)?n:{};var a=["imagePreviewWidth","imagePreviewHeight","imagePreviewQuality"];a.forEach((function(e){r[e]=i.Type.isNumber(l[e])&&l[e]>0?l[e]:r[e]}));if(i.Type.isBoolean(l["imagePreviewUpscale"])){r.imagePreviewUpscale=l["imagePreviewUpscale"]}if(["contain","force","cover"].includes(l["imagePreviewResizeMethod"])){r.imagePreviewResizeMethod=l["imagePreviewResizeMethod"]}if(["image/jpeg","image/png"].includes(l["imagePreviewMimeType"])){r.imagePreviewMimeType=l["imagePreviewMimeType"]}return r}babelHelpers.createClass(t,[{key:"apply",value:function e(t){var i=this;return new Promise((function(e,r){if(!b(t.getFile())){e();return}var n={width:i.imagePreviewWidth,height:i.imagePreviewHeight,mode:i.imagePreviewResizeMethod,upscale:i.imagePreviewUpscale,quality:i.imagePreviewQuality,mimeType:i.imagePreviewMimeType};Ae(t.getFile(),n).then((function(i){var r=i.preview,n=i.width,l=i.height;t.setClientPreview(r,n,l);e()})).catch((function(){e()}))}))}}]);return t}(V);var Me=function(e){babelHelpers.inherits(t,e);function t(e){var r;var n=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};babelHelpers.classCallCheck(this,t);r=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,e));babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"resizeWidth",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"resizeHeight",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"resizeMethod","contain");babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"resizeMimeType","image/jpeg");babelHelpers.defineProperty(babelHelpers.assertThisInitialized(r),"resizeQuality",.92);var l=i.Type.isPlainObject(n)?n:{};if(i.Type.isNumber(l["imageResizeWidth"])&&l["imageResizeWidth"]>0){r.resizeWidth=l["imageResizeWidth"]}if(i.Type.isNumber(l["imageResizeHeight"])&&l["imageResizeHeight"]>0){r.resizeHeight=l["imageResizeHeight"]}if(["contain","force","cover"].includes(l["imageResizeMethod"])){r.resizeMethod=l["imageResizeMethod"]}if(i.Type.isNumber(l["imageResizeQuality"])){r.resizeQuality=Math.min(Math.max(.1,l["imageResizeQuality"]),1)}if(["image/jpeg","image/png"].includes(l["imageResizeMimeType"])){r.resizeMimeType=l["imageResizeMimeType"]}return r}babelHelpers.createClass(t,[{key:"apply",value:function e(t){var i=this;return new Promise((function(e,r){if(!b(t)){return e(t)}if(i.resizeWidth===null&&i.resizeHeight===null){return e(t)}var n={width:i.resizeWidth,height:i.resizeHeight,mode:i.resizeMethod,quality:i.resizeQuality,mimeType:i.resizeMimeType};Ae(t,n).then((function(t){var i=t.preview;e(i)})).catch((function(){e(t)}))}))}}]);return t}(V);var Le={STARTED:0,STOPPED:1};var Ne={VALIDATION:"validation",PREPARATION:"preparation"};var xe=function e(t){return new Promise((function(e,i){if(!t.items){e(t.files?Array.from(t.files):[]);return}var r=Array.from(t.items).filter((function(e){return We(e)})).map((function(e){return Be(e)}));Promise.all(r).then((function(t){var i=[];t.forEach((function(e){i.push.apply(i,e)}));e(i)})).catch(i)}))};var We=function e(t){if("webkitGetAsEntry"in t){var i=t.webkitGetAsEntry();if(i){return i.isFile||i.isDirectory}}return t.kind==="file"};var Be=function e(t){return new Promise((function(e,i){if(je(t)){_e(Ve(t)).then(e).catch(i);return}e([t.getAsFile()])}))};var _e=function e(t){return new Promise((function(e,i){var r=[];var n=0;var l=0;var a=function t(){if(l===0&&n===0){e(r)}};var s=function e(t){n++;var s=t.createReader();var o=function t(){s.readEntries((function(i){if(i.length===0){n--;a();return}i.forEach((function(t){if(t.isDirectory){e(t)}else{l++;t.file((function(e){r.push(e);l--;a()}))}}));t()}),i)};o()};s(t)}))};var je=function e(t){return Ge(t)&&(Ve(t)||{}).isDirectory};var Ge=function e(t){return"webkitGetAsEntry"in t};var Ve=function e(t){return t.webkitGetAsEntry()};var Xe=null;var Je=function e(){if(Xe===null){try{var t=new DataTransfer;var i=new File(["hello"],"my.txt");t.items.add(i);var r=document.createElement("input");r.setAttribute("type","file");r.files=t.files;Xe=r.files.length===1}catch(e){Xe=false}}return Xe};var Qe=function e(t,r){try{var n=new DataTransfer;var l=i.Type.isArray(r)?r:[r];l.forEach((function(e){n.items.add(e)}));t.files=n.files}catch(e){return false}return true};function Ye(e,t,i){if(!t.has(e)){throw new TypeError("attempted to get private field on non-instance")}return i}var qe=new WeakSet;var Ze=new WeakSet;var $e=new WeakSet;var Ke=new WeakSet;var et=new WeakSet;var tt=new WeakSet;var it=new WeakSet;var rt=new WeakSet;var nt=new WeakSet;var lt=function(e){babelHelpers.inherits(l,e);function l(e){var t;babelHelpers.classCallCheck(this,l);t=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(l).call(this));nt.add(babelHelpers.assertThisInitialized(t));rt.add(babelHelpers.assertThisInitialized(t));it.add(babelHelpers.assertThisInitialized(t));tt.add(babelHelpers.assertThisInitialized(t));et.add(babelHelpers.assertThisInitialized(t));Ke.add(babelHelpers.assertThisInitialized(t));$e.add(babelHelpers.assertThisInitialized(t));Ze.add(babelHelpers.assertThisInitialized(t));qe.add(babelHelpers.assertThisInitialized(t));babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"files",[]);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"multiple",false);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"autoUpload",true);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"allowReplaceSingle",true);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"maxParallelUploads",2);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"maxParallelLoads",10);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"acceptedFileTypes",[]);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"ignoredFileNames",[".ds_store","thumbs.db","desktop.ini"]);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"maxFileCount",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"server",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"hiddenFields",new Map);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"hiddenFieldsContainer",null);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"hiddenFieldName","file");babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"assignAsFile",false);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"filters",new Map);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(t),"status",Le.STOPPED);t.setEventNamespace("BX.UI.FileUploader");var r=i.Type.isPlainObject(e)?Object.assign({},e):{};t.multiple=i.Type.isBoolean(r.multiple)?r.multiple:false;t.setAutoUpload(r.autoUpload);t.setMaxParallelUploads(r.maxParallelUploads);t.setMaxParallelLoads(r.maxParallelLoads);t.setAcceptedFileTypes(r.acceptedFileTypes);t.setIgnoredFileNames(r.ignoredFileNames);t.setMaxFileCount(r.maxFileCount);t.setAllowReplaceSingle(r.allowReplaceSingle);t.assignBrowse(r.browseElement);t.assignDropzone(r.dropElement);t.assignPaste(r.pasteElement);t.setHiddenFieldsContainer(r.hiddenFieldsContainer);t.setHiddenFieldName(r.hiddenFieldName);t.setAssignAsFile(r.assignAsFile);var n=i.Type.isPlainObject(r.serverOptions)?r.serverOptions:{};n=Object.assign({},{controller:r.controller,controllerOptions:r.controllerOptions},n);t.server=new j(n);t.subscribeFromOptions(r.events);t.addFilter(Ne.VALIDATION,new X(babelHelpers.assertThisInitialized(t),r));t.addFilter(Ne.VALIDATION,new Q(babelHelpers.assertThisInitialized(t),r));t.addFilter(Ne.VALIDATION,new Fe(babelHelpers.assertThisInitialized(t),r));t.addFilter(Ne.VALIDATION,new Re(babelHelpers.assertThisInitialized(t),r));t.addFilter(Ne.PREPARATION,new Me(babelHelpers.assertThisInitialized(t),r));t.addFilters(r.filters);t.handleBeforeUpload=t.handleBeforeUpload.bind(babelHelpers.assertThisInitialized(t));t.handlePrepareFileAsync=t.handlePrepareFileAsync.bind(babelHelpers.assertThisInitialized(t));t.handleUploadStart=t.handleBeforeUpload.bind(babelHelpers.assertThisInitialized(t));t.handleFileCancel=t.handleFileCancel.bind(babelHelpers.assertThisInitialized(t));t.handleFileStatusChange=t.handleFileStatusChange.bind(babelHelpers.assertThisInitialized(t));t.handleFileStateChange=t.handleFileStateChange.bind(babelHelpers.assertThisInitialized(t));t.addFiles(r.files);return t}babelHelpers.createClass(l,[{key:"addFiles",value:function e(t){var r=this;if(!i.Type.isArrayLike(t)){return}var n=Array.from(t);if(Ye(this,$e,ot).call(this,n)){return}n.forEach((function(e){if(i.Type.isArrayFilled(e)){r.addFile(e[0],e[1])}else{r.addFile(e)}}))}},{key:"addFile",value:function e(i,l){var a=new H(i,l);if(this.getIgnoredFileNames().includes(a.getName().toLowerCase())){return}if(Ye(this,$e,ot).call(this,[a])){return}if(!this.isMultiple()&&this.shouldReplaceSingle()&&this.getFiles().length>0){var s=this.getFiles()[0];this.removeFile(s)}var o=new t.BaseEvent({data:{file:a}});this.emit("File:onBeforeAdd",o);if(o.isDefaultPrevented()){return}Ye(this,qe,at).call(this,a);Ye(this,Ze,st).call(this,a);this.files.push(a);a.setStatus(r.ADDED);this.emit("File:onAddStart",{file:a});a.subscribe("onBeforeUpload",this.handleBeforeUpload);a.subscribe("onPrepareFileAsync",this.handlePrepareFileAsync);a.subscribe("onUploadStart",this.handleUploadStart);a.subscribe("onCancel",this.handleFileCancel);a.subscribe("onStatusChange",this.handleFileStatusChange);a.subscribe("onStateChange",this.handleFileStateChange);if(a.getOrigin()===n.SERVER){a.load()}else{Ye(this,tt,ft).call(this)}}},{key:"start",value:function e(){if(this.getStatus()!==Le.STARTED){this.status=Le.STARTED;this.emit("onStart");Ye(this,et,ht).call(this)}}},{key:"stop",value:function e(){this.status=Le.STOPPED;this.getFiles().forEach((function(e){if(e.isUploading()){e.abort();e.setStatus(r.PENDING)}}));this.emit("onStop")}},{key:"cancel",value:function e(){this.getFiles().forEach((function(e){e.cancel()}))}},{key:"destroy",value:function e(){this.emit("onDestroy");this.getFiles().forEach((function(e){e.cancel()}));for(var t in this){if(this.hasOwnProperty(t)){delete this[t]}}Object.setPrototypeOf(this,null)}},{key:"removeFile",value:function e(t){if(i.Type.isString(t)){t=this.getFile(t)}var n=this.files.findIndex((function(e){return e===t}));if(n>=0){this.files.splice(n,1);t.abort();t.setStatus(r.INIT);this.emit("File:onRemove",{file:t});Ye(this,rt,dt).call(this,t)}}},{key:"getFile",value:function e(t){return this.getFiles().find((function(e){return e.getId()===t}))||null}},{key:"getFiles",value:function e(){return this.files}},{key:"isMultiple",value:function e(){return this.multiple}},{key:"getStatus",value:function e(){return this.status}},{key:"addFilter",value:function e(t,r){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};if(i.Type.isFunction(r)||i.Type.isString(r)){var l=i.Type.isString(r)?i.Reflection.getClass(r):r;if(i.Type.isFunction(l)){r=new l(this,n)}}if(r instanceof V){var a=this.filters.get(t);if(!i.Type.isArray(a)){a=[];this.filters.set(t,a)}a.push(r)}else{throw new Error("FileUploader: a filter must be an instance of FileUploader.Filter.")}}},{key:"addFilters",value:function e(t){var r=this;if(i.Type.isArray(t)){t.forEach((function(e){if(i.Type.isPlainObject(e)){r.addFilter(e.type,e.filter,e.options)}}))}}},{key:"getServer",value:function e(){return this.server}},{key:"assignBrowse",value:function e(t){var r=this;t=i.Type.isElementNode(t)?[t]:t;if(!i.Type.isArray(t)){return}t.forEach((function(e){if(!i.Type.isElementNode(e)){return}var t=null;if(e.tagName==="INPUT"&&e.type==="file"){t=e;if(t.files){r.addFiles(t.files)}var n=t.getAttribute("accept");if(i.Type.isStringFilled(n)){r.setAcceptedFileTypes(n)}}else{t=document.createElement("input");t.setAttribute("type","file");i.Event.bind(e,"click",(function(){t.click()}))}if(r.isMultiple()){t.setAttribute("multiple","multiple")}if(i.Type.isArrayFilled(r.getAcceptedFileTypes())){t.setAttribute("accept",r.getAcceptedFileTypes().join(","))}i.Event.bind(t,"change",(function(){r.addFiles(Array.from(t.files));t.value=""}))}))}},{key:"assignDropzone",value:function e(t){var r=this;t=i.Type.isElementNode(t)?[t]:t;if(!i.Type.isArray(t)){return}t.forEach((function(e){if(!i.Type.isElementNode(e)){return}i.Event.bind(e,"dragover",(function(e){e.preventDefault()}));i.Event.bind(e,"dragenter",(function(e){e.preventDefault()}));i.Event.bind(e,"drop",(function(e){e.preventDefault();e.stopPropagation();xe(e.dataTransfer).then((function(e){r.addFiles(e)}))}))}))}},{key:"assignPaste",value:function e(t){var r=this;t=i.Type.isElementNode(t)?[t]:t;if(!i.Type.isArray(t)){return}t.forEach((function(e){if(!i.Type.isElementNode(e)){return}i.Event.bind(e,"paste",(function(e){e.preventDefault();var t=e.clipboardData;if(!t){return}xe(t).then((function(e){r.addFiles(e)}))}))}))}},{key:"getHiddenFieldsContainer",value:function e(){var t=null;if(i.Type.isStringFilled(this.hiddenFieldsContainer)){t=document.querySelector(this.hiddenFieldsContainer)}else if(i.Type.isElementNode(this.hiddenFieldsContainer)){t=this.hiddenFieldsContainer}return t}},{key:"setHiddenFieldsContainer",value:function e(t){if(i.Type.isStringFilled(t)||i.Type.isElementNode(t)||i.Type.isNull(t)){this.hiddenFieldsContainer=t}}},{key:"getHiddenFieldName",value:function e(){return this.hiddenFieldName}},{key:"setHiddenFieldName",value:function e(t){if(i.Type.isStringFilled(t)){this.hiddenFieldName=t}}},{key:"shouldAssignAsFile",value:function e(){return this.assignAsFile}},{key:"setAssignAsFile",value:function e(t){if(i.Type.isBoolean(t)){this.assignAsFile=t}}},{key:"getTotalSize",value:function e(){return this.getFiles().reduce((function(e,t){return e+t.getSize()}),0)}},{key:"shouldAutoUpload",value:function e(){return this.autoUpload}},{key:"setAutoUpload",value:function e(t){if(i.Type.isBoolean(t)){this.autoUpload=t}}},{key:"getMaxParallelUploads",value:function e(){return this.maxParallelUploads}},{key:"setMaxParallelUploads",value:function e(t){if(i.Type.isNumber(t)&&t>0){this.maxParallelUploads=t}}},{key:"getMaxParallelLoads",value:function e(){return this.maxParallelLoads}},{key:"setMaxParallelLoads",value:function e(t){if(i.Type.isNumber(t)&&t>0){this.maxParallelLoads=t}}},{key:"getUploadingFileCount",value:function e(){return this.getFiles().filter((function(e){return e.isUploading()})).length}},{key:"getAcceptedFileTypes",value:function e(){return this.acceptedFileTypes}},{key:"setAcceptedFileTypes",value:function e(t){var r=this;if(i.Type.isString(t)){t=t.split(",")}if(i.Type.isArray(t)){this.acceptedFileTypes=[];t.forEach((function(e){if(i.Type.isStringFilled(e)){r.acceptedFileTypes.push(e)}}))}}},{key:"getIgnoredFileNames",value:function e(){return this.ignoredFileNames}},{key:"setIgnoredFileNames",value:function e(t){var r=this;if(i.Type.isArray(t)){this.ignoredFileNames=[];t.forEach((function(e){if(i.Type.isStringFilled(e)){r.ignoredFileNames.push(e.toLowerCase())}}))}}},{key:"setMaxFileCount",value:function e(t){if(i.Type.isNumber(t)&&t>0||t===null){this.maxFileCount=t}}},{key:"getMaxFileCount",value:function e(){return this.maxFileCount}},{key:"setAllowReplaceSingle",value:function e(t){if(i.Type.isBoolean(t)){this.allowReplaceSingle=t}}},{key:"shouldReplaceSingle",value:function e(){return this.allowReplaceSingle}},{key:"handleBeforeUpload",value:function e(t){if(this.getStatus()===Le.STOPPED){t.preventDefault();this.start()}else{if(this.getUploadingFileCount()>=this.getMaxParallelUploads()){t.preventDefault()}}}},{key:"handlePrepareFileAsync",value:function e(t){var r=this;return new Promise((function(e,n){var l=t.getData(),a=l.file;Ye(r,Ke,ut).call(r,Ne.PREPARATION,a).then((function(t){if(i.Type.isFile(t)){e(t)}else{e(a)}})).catch((function(e){return n(e)}))}))}},{key:"handleUploadStart",value:function e(t){var i=t.getTarget();this.emit("File:onUploadStart",{file:i})}},{key:"handleFileCancel",value:function e(t){var i=t.getTarget();this.emit("File:onCancel",{file:i});this.removeFile(i)}},{key:"handleFileStatusChange",value:function e(t){var i=t.getTarget();this.emit("File:onStatusChange",{file:i})}},{key:"handleFileStateChange",value:function e(t){var i=t.getTarget();this.emit("File:onStateChange",{file:i});if(i.isComplete()){Ye(this,it,ct).call(this,i)}}}]);return l}(t.EventEmitter);var at=function e(t){var i=this;var l=t.getOrigin()===n.SERVER?this.getServer().createLoadController():this.getServer().createClientLoadController();l.subscribeFromOptions({onError:function e(n){t.setStatus(r.LOAD_FAILED);i.emit("File:onError",{file:t,error:n.getData().error});Ye(i,tt,ft).call(i)},onProgress:function e(r){i.emit("File:onLoadProgress",{file:t,progress:r.getData().progress})},onLoad:function e(l){if(t.getOrigin()===n.SERVER){t.setFile(l.getData().fileInfo);t.setStatus(r.COMPLETE);i.emit("File:onAdd",{file:t});i.emit("File:onLoadComplete",{file:t});i.emit("File:onComplete",{file:t});return}Ye(i,Ke,ut).call(i,Ne.VALIDATION,t).then((function(){if(t.isUploadable()){t.setStatus(r.PENDING);i.emit("File:onAdd",{file:t});i.emit("File:onLoadComplete",{file:t});if(i.shouldAutoUpload()){t.upload()}}else{t.setStatus(r.COMPLETE);i.emit("File:onAdd",{file:t});i.emit("File:onLoadComplete",{file:t});i.emit("File:onComplete",{file:t})}Ye(i,tt,ft).call(i)})).catch((function(e){t.setStatus(r.LOAD_FAILED);i.emit("File:onError",{file:t,error:e});i.emit("File:onAdd",{file:t,error:e});Ye(i,tt,ft).call(i)}))}});t.setLoadController(l)};var st=function e(t){var i=this;var n=this.getServer().createUploadController();if(!n){return}n.subscribeFromOptions({onError:function e(n){t.setStatus(r.UPLOAD_FAILED);i.emit("File:onError",{file:t,error:n.getData().error});Ye(i,et,ht).call(i)},onProgress:function e(r){i.emit("File:onUploadProgress",{file:t,progress:r.getData().progress})},onUpload:function e(n){t.setStatus(r.COMPLETE);t.setFile(n.getData().fileInfo);i.emit("File:onUploadComplete",{file:t});i.emit("File:onComplete",{file:t});Ye(i,et,ht).call(i)}});t.setUploadController(n)};var ot=function e(t){var i=t.length;var r=this.getFiles().length;if(!this.isMultiple()&&i>1){return true}var n;if(this.isMultiple()){n=this.getMaxFileCount()}else{n=this.shouldReplaceSingle()?null:1}if(n!==null&&r+i>n){var l=new S("MAX_FILE_COUNT_EXCEEDED",{maxFileCount:n});this.emit("onMaxFileCountExceeded",{error:l});this.emit("onError",{error:l});return true}return false};var ut=function e(t){var i=this;for(var r=arguments.length,n=new Array(r>1?r-1:0),l=1;l<r;l++){n[l-1]=arguments[l]}return new Promise((function(e,r){var l=babelHelpers.toConsumableArray(i.filters.get(t)||[]);if(l.length===0){e();return}var a=l.shift();l.reduce((function(e,t){return e.then((function(){return t.apply.apply(t,n)}))}),a.apply.apply(a,n)).then((function(t){return e(t)})).catch((function(e){return r(e)}))}))};var ht=function e(){if(this.getStatus()!==Le.STARTED){return}var t=this.getMaxParallelUploads();var i=this.getUploadingFileCount();var r=this.getFiles().filter((function(e){return e.isReadyToUpload()}));var n=r.length;if(i<t){var l=Math.min(t-i,r.length);for(var a=0;a<l;a++){var s=r[a];s.upload()}}if(i===0&&n===0){this.status=Le.STOPPED;this.emit("onUploadComplete")}};var ft=function e(){var t=this.getMaxParallelLoads();var i=this.getFiles().filter((function(e){return e.isLoading()})).length;var l=this.getFiles().filter((function(e){return e.getStatus()===r.ADDED&&e.getOrigin()===n.CLIENT}));if(i<t){var a=Math.min(t-i,l.length);for(var s=0;s<a;s++){var o=l[s];o.load()}}};var ct=function e(t){var r=this.getHiddenFieldsContainer();if(!r||this.hiddenFields.has(t.getId())){return}var l=i.Type.isNumber(t.getServerId());if(l){return}var a=t.getOrigin()===n.CLIENT&&!t.isUploadable()&&this.shouldAssignAsFile()&&Je();var s=document.createElement("input");s.type=a?"file":"hidden";s.name=this.getHiddenFieldName()+(this.isMultiple()?"[]":"");if(a){i.Dom.style(s,{visibility:"hidden",left:0,top:0,width:0,height:0,position:"absolute","pointer-events":"none"});Qe(s,t.getFile())}else if(t.getServerId()!==null){s.value=t.getServerId()}r.appendChild(s);this.hiddenFields.set(t.getId(),s);Ye(this,nt,pt).call(this)};var dt=function e(t){var r=this.hiddenFields.get(t.getId());if(r){i.Dom.remove(r);this.hiddenFields.delete(t.getId())}};var pt=function e(){var t=this;var i=this.getHiddenFieldsContainer();if(!i){return}this.getFiles().forEach((function(e){var r=t.hiddenFields.get(e.getId());if(r){i.appendChild(r)}}))};var vt=function e(t){return/^image/.test(t.type)};var gt=Object.freeze({formatFileSize:y,getFileExtension:v,getFilenameWithoutExtension:ke,getExtensionFromType:u,getArrayBuffer:Y,isDataUri:d,isImage:vt,isResizableImage:b,getImageSize:Te,resizeImage:Ae,loadImage:Pe,isValidFileType:J,canAppendFileToForm:Je,assignFileToInput:Qe,createFileFromBlob:f,createBlobFromDataUri:p,createUniqueId:o,createWorker:we});e.Uploader=lt;e.UploaderStatus=Le;e.FileStatus=r;e.FileOrigin=n;e.FilterType=Ne;e.Helpers=gt})(this.BX.UI.FileUploader=this.BX.UI.FileUploader||{},BX.Event,BX);
//# sourceMappingURL=ui.file-uploader.bundle.map.js